<template>
    <el-row>
        <el-col :span="2">namespace:</el-col>
        <el-col :span="2">{{ namespace }}</el-col>
        <el-col :span="2">name:</el-col>
        <el-col :span="4">{{ name }}</el-col>
        <el-col :span="2">container:</el-col>
        <el-col :span="6">
            <el-select
                id="select_containers"
                v-model="currentContainer"
                filterable
                placeholder="Select containers"
                :fit-input-width="true"
                :clearable="true"
                style="width:100%"
                @change="loadLog()"
            >
                <el-option v-for="item in containers" :key="item" :label="item" :value="item"></el-option>
            </el-select>
        </el-col>
        <el-col :span="2"><el-button @click.native="loadLog()" >刷新</el-button></el-col>
        <el-col :span="2"><el-button @click.native="Shell()" >Shell</el-button></el-col>
    </el-row>
    <el-row style="overflow: auto;height:80%;" v-loading="loading">
        <pre >{{ content }}</pre>
    </el-row>
</template>
<script>
import { ref } from "vue";
export default {
    name: 'PodLog',
    components: {},
    setup() {
        const loading =ref(false)
        const content = ref(``);
        const currentContainer = ref(``);
        const containers = ref([])
        const kind = ref(``)
        const namespace = ref(``)
        const name = ref(``)
        return {
            loading,
            content,
            currentContainer,
            containers,
            kind,
            namespace,
            name,
            async loadLog() {
                loading.value =true
                let log = await window.k8s_GetPodLog(namespace.value, name.value, currentContainer.value)
                content.value = log
                loading.value =false
            },
            setMeta(row) {
                kind.value = row.kind
                name.value = row.metadata.name
                namespace.value = row.metadata.namespace
                var _containers = []
                for (var i = 0, s = row.spec.containers.length; i < s; i++) {
                    if (i == 0) {
                        currentContainer.value = row.spec.containers[i].name
                    }
                    _containers.push(row.spec.containers[i].name)
                }
                containers.value = _containers
            },
            async Shell(){
               let err= await window.k8s_OpenPodShell(namespace.value, name.value, currentContainer.value)
               if(err){
                   console.log(err)
               }
            }
        };
    },
}
</script>
<style>
pre {
white-space: pre-wrap;
word-wrap: break-word;
text-align:left;
}
</style>